package com.yjkf.zh.test.thread;

public class MyRunnable{
    /**
     * 代理设计模式，执行start会调用Thread的run()方法，run()方法在去调用runable接口子类被覆盖过的run()方法。
     * @param args
     */
    public static void main(String[] args){
        /*Thread threada=new Thread(new RunnableTest("线程a"));
        Thread threadb=new Thread(new RunnableTest("线程b"));
        Thread threadc=new Thread(new RunnableTest("线程c"));

        threada.start();
        threadb.start();
        threadc.start();*/

/*        for(int x = 0;x<3;x++){
            String name = "线程对象-"+x;
            Runnable run=()->{
                for(int y = 0;y<10;y++){
                    System.out.println(name+"线程"+y);
                }
            };
            new Thread(run).start();
        }*/

    Ticket thread1 = new Ticket();
        new Thread(thread1).start();
        new Thread(thread1).start();
    }
}

class RunnableTest implements Runnable{
    private String name;

    public RunnableTest(String name){
        this.name = name;
    }

    @Override
    public void run() {
        for(int i = 0;i<10;i++){
            System.out.println(this.name+"线程执行..");
        }
    }
}

class Ticket implements Runnable{

    int ticket = 5;

    @Override
    public void run() {
        for(int i = 0 ;i<10;i++){
            if(this.ticket>0){
                System.out.println("卖票"+this.ticket--);
            }
        }
    }
}